home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / web / cweb.lha / cweb / webman.tex (.txt) < prev   
LaTeX Document  |  1990-07-13  |  58KB  |  1,110 lines

  1. \input cwebmac
  2. \parskip 0pt plus 1pt
  3. \def\RA{\char'31 } % right arrow
  4. \def\hang{\hangindent 4em\ignorespaces}
  5. \font\ninerm=cmr9
  6. \font\ninett=cmtt9
  7. \font\eighttt=cmtt8
  8. \def\Pascal{Pascal}
  9. \def\cee{C}
  10. \font\quoterm=cmssq8
  11. \font\quoteit=cmssqi8
  12. \def\pb{\.{|...|}}
  13. \def\v{\.{\char'174}} % vertical (|) in typewriter font
  14. \def\lpile{\def\cr{\hfill\endline}\matrix} % I only use \lpile by itself
  15. \outer\def\section #1.{\penalty-50\vskip 12pt plus 3pt minus 3pt
  16.   \noindent{\bf #1.}\quad\ignorespaces}
  17. \def\titlepage{T}
  18. \def\lheader{\mainfont\the\pageno\hfill\sc\runninghead\hfill}
  19. \def\rheader{\hfill\ifnum\the\pageno=1\else\sc\runninghead\hfill
  20.   \mainfont\the\pageno\fi}
  21. \def\runninghead{{\tentt CWEB} USER MANUAL}
  22. \def\narrower{\medskip\bgroup\rightskip=24pt\leftskip=24pt}
  23. \def\endnarrower{\medskip\egroup}
  24. % This verbatim mode assumed that no ? appears in the text being copied.
  25. \def\verbatim{\begingroup
  26.   \def\do##1{\catcode`##1=12 } \dospecials
  27.   \parskip 0pt \parindent 0pt
  28.   \catcode`\ =13 \catcode`\^^M=13
  29.   \tt \catcode`\?=0 \verbatimdefs \verbatimgobble}
  30. {\catcode`\^^M=13{\catcode`\ =13\gdef\verbatimdefs{\def^^M{\ \par}\let =\ }} %
  31.   \gdef\verbatimgobble#1^^M{}}
  32. \centerline{\titlefont A \cee\ version of {\ttitlefont WEB}}
  33. \vskip 15pt plus 3pt minus 3pt
  34. \section Introduction.
  35. This document describes a version of Don Knuth's \.{WEB} system of
  36. structured documentation, adapted to \cee\ by Silvio Levy.  This version
  37. was entirely rewritten in \cee, and many changes were made to take
  38. advantage of features offered by \cee\ but non-existent in \Pascal.
  39. The bulk of this document, not counting appendixes~A--E, consists of
  40. quotes from Knuth's memo ``The \.{WEB} System of Structured
  41. Documentation;'' these quotes are clearly distinguished by their indentation,
  42. and apart from the substitution of the word ``\cee'' for ``\Pascal''
  43. and of `\.{@c}' for `\.{@p}'
  44. all other changes to them are explicitly indicated.
  45. This also serves to indicate which commands and features are common
  46. to both versions of \.{WEB} and which are characteristic of this
  47. version (of course if you're new to \.{WEB} you don't
  48. have to worry about this).
  49. \narrower
  50. The philosophy behind \.{WEB} is
  51. that an experienced system programmer, who wants to provide the best
  52. possible documentation of his or her software products, needs two things
  53. simultaneously:  a language like \TeX\ for formatting, and a language like
  54. \cee\ for programming. Neither type of language can provide the
  55. best documentation by itself; but when both are appropriately combined, we
  56. obtain a system that is much more useful than either language separately.
  57. The structure of a software program may be thought of as a ``web'' that is
  58. made up of many interconnected pieces. To document such a program, we want
  59. to explain each individual part of the web and how it relates to its
  60. neighbors. The typographic tools provided by \TeX\ give us an opportunity
  61. to explain the local structure of each part by making that structure
  62. visible, and the programming tools provided by \cee\ make it possible
  63. for us to specify the algorithms formally and unambiguously. By combining
  64. the two, we can develop a style of programming that maximizes our ability
  65. to perceive the structure of a complex piece of software, and at the same
  66. time the documented programs can be mechanically translated into a working
  67. software system that matches the documentation. \dots
  68. Besides providing a documentation tool, \.{WEB} enhances the \cee\
  69. language by providing \dots\ the
  70. ability to permute pieces of the program text, so that a large system can
  71. be understood entirely in terms of small modules and their local
  72. interrelationships.  The \.{TANGLE} program is so named because it takes a
  73. given web and moves the modules from their web structure into the order
  74. required by \cee; the advantage of programming in \.{WEB} is that the
  75. algorithms can be expressed in ``untangled'' form, with each module
  76. explained separately.  The \.{WEAVE} program is so named because it takes
  77. a given web and intertwines the \TeX\ and \cee\ portions contained in
  78. each module, then it knits the whole fabric into a structured document.
  79. (Get it? Wow.)  Perhaps there is some deep connection here with the fact
  80. that the German word for ``weave'' is ``{\it web\/}'', and the
  81. corresponding Latin imperative is ``{\it texe\/}''!
  82. \endnarrower
  83. A user of this version of \.{WEB} should be fairly familiar with the \cee\
  84. programming language.  A minimal amount of acquaintance with \TeX\ is also
  85. desirable, but in fact it can be acquired as one uses \.{WEB}, since
  86. straight text can be typeset in \TeX\ with virtually no knowledge of
  87. the language.  To someone familiar with \cee\ and \TeX\ the amount of
  88. effort necessary to learn the commands of \.{WEB} is small.
  89. \section The language.
  90. As mentioned above, in writing a \.{WEB} program the user keeps the
  91. \cee\ code and the documentation in the same file, called the \.{WEB}
  92. file and generally named \.{something.web}.  The command
  93. `\.{weave something}' creates an output file \.{something.tex}, which
  94. can then be fed to \TeX, yielding a ``pretty printed'' version of
  95. \.{something.web} that correctly handles
  96. typographic details like page layout and the use of indentation,
  97. italics, boldface, etc., and that includes extensive cross-index
  98. information that is gathered automatically.  Similarly, if you run the
  99. command \.{tangle something} you will get a \cee\ file \.{something.c},
  100. with can then be compiled to yield executable code.
  101. \narrower
  102. Two kinds of material go into \.{WEB} files: \TeX\ text and \cee\ text.
  103. A programmer writing in \.{WEB} should be thinking both of the
  104. documentation and of the \cee\ program that he or she is creating;
  105. i.e., the programmer should be instinctively aware of the different
  106. actions that \.{WEAVE} and \.{TANGLE} will perform on the \.{WEB} file.
  107. \TeX\ text is essentially copied without change by \.{WEAVE}, and it is
  108. entirely deleted by \.{TANGLE}, since the \TeX\ text is ``pure
  109. documentation.'' \cee\ text, on the other hand, is formatted by
  110. \.{WEAVE} and it is shuffled around by \.{TANGLE}, according to rules that
  111. will become clear later. For now the important point to keep in mind is
  112. that there are two kinds of text. Writing \.{WEB} programs is something
  113. like writing \TeX\ documents, but with an additional ``\cee\ mode''
  114. that is added to \TeX's horizontal mode, vertical mode, and math mode.
  115. A \.{WEB} file is built up from units called {\sl modules\/} that are more
  116. or less self-contained.  Each module has three parts:
  117. \yskip\item{1)} A \TeX\ part, containing explanatory material about what
  118. is going on in the module.
  119. \item{2)} A definition part, containing macro definitions that serve as
  120. abbreviations for \cee\ constructions that would be less comprehensible
  121. if written out in full each time [they are turned by \.{TANGLE} into
  122. preprocessor macro definitions].
  123. \item{3)} A \cee\ part, containing a piece of the program that
  124. \.{TANGLE} will produce. This \cee\ code should ideally be about a
  125. dozen lines long, so that it is easily comprehensible as a unit and so
  126. that its structure is readily perceived.
  127. \yskip\noindent The three parts of each module must appear in this order;
  128. i.e., the \TeX\ commentary must come first, then the definitions, and
  129. finally the \cee\ code. Any of the parts may be empty.
  130. A module begins with [either of the two] symbols `\.{@\ }' or `\.{@*}', where
  131. `\.{\ }' denotes a blank space. A module ends
  132. at the beginning of the next module (i.e., at the next
  133. `\.{@\ }' or `\.{@*}'), or at the end of the file, whichever comes first.
  134. The \.{WEB} file may also contain material that is not part of any module
  135. at all, namely the text (if any) that occurs before the first module.
  136. Such text is said to be ``in limbo''; it is ignored by \.{TANGLE}
  137. and copied essentially verbatim by \.{WEAVE}, so its function is to
  138. provide any additional formatting instructions that may be desired in the
  139. \TeX\ output. Indeed, it is customary to begin a \.{WEB} file with
  140. \TeX\ code in limbo that loads special fonts, defines special macros,
  141. changes the page sizes, and/or produces a title page.
  142. Modules are numbered consecutively, starting with 1; these numbers appear
  143. at the beginning of each module of the \TeX\ documentation, and they appear
  144. as bracketed comments at the beginning of the code generated by that
  145. module in the \cee\ program.
  146. Fortunately, you never mention these numbers yourself when you are writing
  147. in \.{WEB}. You just say `\.{@\ }' or `\.{@*}' at the beginning of each
  148. new module, and the numbers are supplied automatically by \.{WEAVE} and
  149. \.{TANGLE}. As far as you are concerned, a module has a
  150. name instead of a number; such a name is specified by writing
  151. `\.{@<}' followed by \TeX\ text followed by `\.{@>}'. When \.{WEAVE}
  152. outputs a module name, it replaces the `\.{@<}' and `\.{@>}' by
  153. angle brackets and inserts the module number in small type. Thus, when you
  154. read the output of \.{WEAVE} it is easy to locate any module that is
  155. referred to in another module.
  156. For expository purposes, a module name should be a good description of the
  157. contents of that module, i.e., it should stand for the abstraction
  158. represented by the module; then the module can be ``plugged into'' one or
  159. more other modules so that the unimportant details of its inner workings
  160. are suppressed.  A module name therefore ought to be long enough to convey
  161. the necessary meaning. Unfortunately, however, it is laborious to type
  162. such long names over and over again, and it is also difficult to specify a
  163. long name twice in exactly the same way so that \.{WEAVE} and \.{TANGLE}
  164. will be able to match the names to the modules. Therefore a module name
  165. can be abbreviated after its first appearance in the \.{WEB} file, by
  166. typing `\.{@<$\alpha$...@>}', where $\alpha$ is any string that is a prefix of
  167. exactly one module name that appears in the file. For example, `\.{@<Clear
  168. the arrays@>}' can be abbreviated to `\.{@<Clear...@>}' if no other module
  169. name begins with the five letters `\.{Clear}'. Module names must otherwise
  170. match character for character, except that consecutive blank spaces and/or
  171. tab marks are treated as equivalent to single spaces, and such spaces are
  172. deleted at the beginning and end of the name. Thus, `\.{@< Clear { }the
  173. arrays @>}' will also match the name in the previous example.
  174. We have said that a module begins with `\.{@\ }' or `\.{@*}', but we
  175. didn't say how it gets divided up into a \TeX\ part, a definition part,
  176. and a \cee\ part. The definition part begins with the first appearance
  177. of `\.{@d}' or `\.{@f}' in the module, and the \cee\ part begins with
  178. the first appearance of `\.{@c}' or `\.{@<}'. The latter option `\.{@<}'
  179. stands for the beginning of a module name, which is the name of the module
  180. itself. An equals sign (\.=) must follow the `\.{@>}' at the end of this
  181. module name; you are saying, in effect, that the module name stands for
  182. the \cee\ text that follows, so you say `$\langle\,$module
  183. name$\,\rangle=\null$\cee\ text'. Alternatively, if the \cee\ part
  184. begins with `\.{@c}' instead of a module name, the current module is said
  185. to be {\sl unnamed}. Note that module names cannot appear in the
  186. definition part of a module, because the first `\.{@<}' in a module
  187. signals the beginning of its \cee\ part.  Any number of module names
  188. might appear in the \cee\ part, however, once it has started.
  189. The general idea of \.{TANGLE} is to make a \cee\ program out of these
  190. modules in the following way: First all [the macro definitions
  191. indicated by `\.{@d}' are turned into \cee\ preprocessor macro definitions
  192. and copied down.  Then] the \cee\ parts of unnamed modules are copied down
  193. [with comments removed], in order; this constitutes the initial
  194. approximation $T_0$ to the text of the program. (There should be at least
  195. one unnamed module, otherwise there will be no program.) Then all module
  196. names that appear in the initial text $T_0$ are replaced by the \cee\
  197. parts of the corresponding modules, and this substitution process
  198. continues until no module names remain. \dots
  199. If the same name has been given to more than one module, the \cee\ text
  200. for that name is obtained by putting together all of the \cee\ parts in
  201. the corresponding modules. This feature is useful, for example, in a
  202. module named `Global variables in the outer block', since one can then
  203. declare global variables in whatever modules those variables are
  204. introduced. When several modules have the same name, \.{WEAVE} assigns the
  205. first module number as the number corresponding to that name, and it
  206. inserts a note at the bottom of that module telling the reader to `See
  207. also sections so-and-so'; this footnote gives the numbers of all the other
  208. modules having the same name as the present one. The \cee\ text
  209. corresponding to a module is usually formatted by \.{WEAVE} so that the
  210. output has an equivalence sign in place of the equals sign in the \.{WEB}
  211. file; i.e., the output says `$\langle\,$module
  212. name$\,\rangle\equiv\null$\cee\ text'. However, in the case of the second
  213. and subsequent appearances of a module with the same name, this `$\equiv$'
  214. sign is replaced by `$\mathrel+\equiv$', as an indication that the \cee\
  215. text that follows is being appended to the \cee\ text of another module.
  216. \endnarrower
  217. As \.{TANGLE} starts and leaves modules, it writes down preprocessor
  218. \.{\#line} commands, for the benefit of the compiler.  This means that
  219. when the compiler gives you error messages, or when you debug your program,
  220. the messages refer to line number in the \.{WEB} file, and not in the
  221. \cee\ file.  In most cases you can even forget about the \cee\ file altogether.
  222. \narrower
  223. The general idea of \.{WEAVE} is to make a \.{TEX} file from the \.{WEB}
  224. file in the following way: The first line of the \.{TEX} file
  225. [tells \TeX\ to input a file with] macros that
  226. define \.{WEB}'s documentation conventions. The next lines of the file
  227. will be copied from whatever \TeX\ text is in limbo before the first
  228. module.  Then comes the output for each module in turn, possibly
  229. interspersed with end-of-page marks.  Finally, \.{WEAVE} will generate a
  230. cross-reference index that lists each module number in which each \cee\
  231. identifier appears, and it will also generate an alphabetized list
  232. of the module names, as well as a table of contents that
  233. shows the page and module numbers for each ``starred'' module.
  234. What is a ``starred'' module, you ask? A module that begins with `\.{@*}'
  235. instead of `\.{@\ }' is slightly special in that it denotes a new major
  236. group of modules. The `\.{@*}' should be followed by the title of this
  237. group, followed by a period. Such modules will always start on a new page
  238. in the \TeX\ output, and the group title will appear as a running headline
  239. on all subsequent pages until the next starred module. The title will also
  240. appear in the table of contents, and in boldface type at the beginning of
  241. its module. Caution:  Do not use \TeX\ control sequences in such titles,
  242. unless you know that the \.{webmac} macros will do the right thing with
  243. them. The reason is that these titles are converted to uppercase when
  244. they appear as running heads, and they are converted to boldface when they
  245. appear at the beginning of their modules, and they are also written out to
  246. a table-of-contents file used for temporary storage while \TeX\ is
  247. working; whatever control sequences you use must be meaningful in all
  248. three of these modes.
  249. The \TeX\ output produced by \.{WEAVE} for each module consists of
  250. the following: First comes the module number (e.g., `\.{\\M123.}'
  251. at the beginning of module 123, except that `\.{\\N}' appears in place of
  252. `\.{\\M}' at the beginning of a starred module). Then comes the
  253. \TeX\ part of the module, copied almost verbatim except as noted
  254. below. Then comes the definition part and the \cee\ part, formatted
  255. so that there will be a little extra space between them if both are
  256. nonempty. The definition and \cee\ parts are obtained by inserting
  257. a bunch of funny looking \TeX\ macros into the \cee\ program; these
  258. macros handle typographic details about fonts and proper math spacing,
  259. as well as line breaks and indentation.
  260. When you are typing \TeX\ text, you will probably want to make frequent
  261. reference to variables and other quantities in your \cee\ code, and you
  262. will want those variables to have the same typographic treatment
  263. when they appear in your text as when they appear in your
  264. program.  Therefore the \.{WEB} language allows you to get the effect of
  265. \cee\ editing within \TeX\ text, if you place `\.|' marks before and
  266. after the \cee\ material. For example, suppose you want to say something
  267. like this:
  268. $$\hbox{If \\{pa} is declared as \&{int} ${*}\\{pa}$, the assignment
  269. $\\{pa}={\amp}\|a[\O{0}]$ sets \\{pa} to point to the zeroth element of \|a.}$$
  270. The \TeX\ text would look like this in your \.{WEB} file:
  271. $$\lpile{\.{If |pa| is declared as |int *pa|, the}\cr
  272. \.{assignment |pa=\&a[0]| sets |pa| to point
  273. to the zeroth element of |a|.}\cr}$$
  274. And \.{WEAVE} translates this into something you are glad you didn't have
  275. to type:
  276. $$\lpile{\.{If \\\\\{pa\} is declared as \\\&\{int\} \$\{*\}\\\\\{pa\}\$,
  277. the}\cr
  278.   \.{assignment \$\\\\\{pa\}=\{\\amp\}\\|a[\\O\{0\}]\$
  279.   sets \\\\\{pa\} to point to the zeroth element of \\|a.}\cr}$$
  280. Incidentally, the cross-reference index that \.{WEAVE} would make, in
  281. the presence of a comment like this, would include
  282. the current module number as one of the index entries for \\{pa},
  283. even though \\{pa} might not appear in the \cee\ part of
  284. this module. Thus, the index covers references to identifiers in
  285. the explanatory comments as well as in the program itself; you will
  286. soon learn to appreciate this feature. However, the identifiers
  287. \&{int} and \|a\ would not be indexed,
  288. because \.{WEAVE} does not make index entries for reserved words or
  289. single-letter identifiers. Such identifiers are felt to be so ubiquitous
  290. that it would be pointless to mention every place where they occur. \dots
  291. Although a module begins with \TeX\ text and ends with \cee\ text, we
  292. have noted that the dividing line isn't sharp, since \cee\ text can be
  293. included in \TeX\ text if it is enclosed in `\pb'.  Conversely, \TeX\ text
  294. also appears frequently within \cee\ text, because everything in
  295. comments (i.e., between \.{/*} and right \.{*/}) is treated as \TeX\ text.
  296. Furthermore, a module name consists of \TeX\ text; thus, a \.{WEB} file
  297. typically involves constructions like `\.{if} \.{(x==0)}
  298. \.{@<Empty} \.{the} \.{|buffer|} \.{array@>}' where we go back and forth
  299. between \cee\ and \TeX\ conventions in a natural way.
  300. \endnarrower
  301. \section Macros.
  302. A \.{@d} followed by
  303. $$`\\{identifier}\.{ }\hbox{\cee\ text'}\qquad\hbox{or}\qquad
  304. \\{identifier}\.(\\{par1},\dots,\\{parn}\.)\.{ }\hbox{\cee\ text'},$$
  305. where there is no blank between the
  306. \\{identifier} and the parentheses in the second case, is
  307. transformed by \.{TANGLE} into a preprocessor command, starting with
  308. \.{\#define}, which is printed at the top of the file.  If
  309. for any reason you need a \.{\#define} command at a specific spot in
  310. your \cee\ file, you can treat it as \cee\ code, instead of as a
  311. \.{WEB} macro.
  312. A `\.{@d}' macro definition can go on for several lines, and the
  313. newlines don't have to be protected by backslashes, since \.{TANGLE}
  314. itself inserts the backslashes.
  315. \section Strings and constants.
  316. If you want a string, delimited by pairs of \.' or \.", to appear in
  317. the \cee\ file, you can type it exactly so in the \.{WEB} file, except
  318. that the character `\.@' should be typed `\.{@@}' (it becomes a
  319. control code, the only one that can appear in strings; see below).
  320. Newlines should be protected by backslashes.
  321. In particular, the string `\.{'A'}' in the \.{WEB} file will be copied by
  322. \.{TANGLE} into the \cee\ file, and will be interpreted by the \cee\
  323. compiler as the machine's code for `\.A'.  \.{WEB} offers a
  324. way to uniformize the value of character constants, so that readily
  325. portable programs can be easily written (\.{WEB} itself uses this
  326. facility): if you write `\.{@'A'}' in the \.{WEB} file, \.{TANGLE} will
  327. translate this into the ASCII code for `\.A', so the value of this
  328. constant does not depend on the character set.  This works for all the
  329. visible characters of the ASCII character set codes $40_8$ to $176_8$
  330. (i.e., octal), as well as the standard \cee\ escape sequences
  331. \.{\\n}, \.{\\t}, \.{\\b}, \.{\\r} and \.{\\f}.
  332. Speaking of octal constants, \TeX\ and \cee\ have (unfortunately)
  333. incompatible ways to refer to octal and hex constants.  In \TeX\ you
  334. make a constant octal or hexadecimal by prepending \.' or \.",
  335. respectively, to it; in \cee\ the constant should be preceded by \.0
  336. or \.{0x}.  In \.{WEB} it seems reasonable to let each convention hold
  337. in its respective realm; so in \cee\ text you get $40_8$ by typing
  338. `\.{040}', which \.{TANGLE} faithfully copies into the \cee\ file (for
  339. the compiler's benefit) and which \.{WEAVE} prints as $\O{\~40}$
  340. (for the benefit of \TeX\ users).  For consistency, then, you
  341. should type `\.{|040|}' in the \TeX\ part of the module.  (I'm not entirely
  342. sure that this is what \.{WEB} should do; suggestions are welcome.)
  343. \section Control codes.
  344. A \.{WEB} {\sl control code\/}
  345. is a two-character combination of which the first is `\.@'.
  346. We've already seen the meaning of several control codes; here is a
  347. complete list of all of them.
  348. \narrower
  349. The letters $L$, $T$,
  350. $C$, $M$, $\\{Co}$, and/or $S$ following each code indicate whether or not that
  351. code is allowable in limbo, in \TeX\ text, in \cee\ text, in module
  352. names, in comments, and/or in strings.  A bar over such a letter means
  353. that the control code terminates the present part of the \.{WEB} file; for
  354. example, $\overline L$ means that this control code ends the limbo material
  355. before the first module.
  356. \gdef\@#1[#2] {\yskip\hangindent 2em\noindent\.{@#1\unskip
  357.   \spacefactor1000{ }}$[#2]$\quad}
  358. \def\oP{\overline C}
  359. \def\oT{\overline T}
  360. \@@ [\\{Co},L,M,C,S,T] A double \.@ denotes the single character `\.@'. This is
  361. the only control code that is legal in limbo, in comments, and in strings.
  362. \@\ [\overline L,\oP,\oT] This denotes the beginning of a new
  363. (unstarred) module. A tab mark or end-of-line (carriage return)
  364. is equivalent to a space when it follows an \.@ sign.
  365. \@* [\overline L,\oP,\oT] This denotes the beginning of a new starred
  366. module, i.e., a module that begins a new major group. The title of the new
  367. group should appear after the \.{@*}, followed by a period. As explained
  368. above, \TeX\ control sequences should be avoided in such titles unless
  369. they are quite simple. When \.{WEAVE} and \.{TANGLE} read a \.{@*}, they
  370. print an asterisk followed by the current module number, so that the user
  371. can see some indication of progress. The very first module should be starred.
  372. \@d [\oP,\oT] Macro definitions begin with \.{@d} (or \.{@D}), followed by
  373. [an identifier and \cee\ text as explained earlier].
  374. \@f [\oP,\oT] Format definitions begin with \.{@f} (or \.{@F}); they cause
  375. \.{WEAVE} to treat identifiers in a special way when they appear in
  376. \cee\ text. [The general form of a format definition is `\.{@f} \|l
  377. \|r', followed by an optional comment enclosed between
  378. \.{/*} and \.{*/}, where \|l and \|r
  379. are identifiers;] \.{WEAVE} will subsequently treat identifier \|l as it
  380. currently treats \|r. This feature allows a \.{WEB} programmer to invent
  381. new reserved words and/or to unreserve some of \cee's reserved
  382. identifiers. [However, the need to do this
  383. should arise very seldom, since \.{WEAVE} knows that identifiers being
  384. defined with a \&{typedef} should become reserved words.]
  385. The definition part of each module consists of any number of
  386. macro definitions (beginning with \.{@d}) and format definitions (beginning
  387. with \.{@f}), intermixed in any order.
  388. \@c [\oP,\oT] The \cee\ part of an unnamed module begins with \.{@c}
  389. (or \.{@C}). This causes \.{TANGLE} to append the following \cee\ code
  390. to the initial program text $T_0$ as explained above. The \.{WEAVE}
  391. processor does not cause a `\.{@c}' to appear explicitly in the \TeX\
  392. output, so if you are creating a \.{WEB} file based on a \TeX-printed
  393. \.{WEB} documentation you have to remember to insert \.{@c} in the
  394. appropriate places of the unnamed modules.
  395. Because of the rules by which every module is broken into three parts,
  396. the control codes `\.{@d}', `\.{@f}', and `\.{@c}' are not allowed to occur
  397. once the \cee\ part of a module has begun.
  398. \@< [C,\oT] A module name begins with \.{@<} followed by \TeX\ text followed
  399. by \.{@>}; the \TeX\ text should not contain any \.{WEB} control sequences
  400. except \.{@@}, unless these control sequences appear in \cee\ text that
  401. is delimited by \pb. The module name may be abbreviated, after its first
  402. appearance in a \.{WEB} file, by giving any unique prefix followed by \.{...},
  403. where the three dots immediately precede the closing \.{@>}. Module names may
  404. not appear in \cee\ text that is enclosed in \pb, nor may they appear
  405. in the definition part of a module (since the appearance of a module name
  406. ends the definition part and begins the \cee\ part). \dots
  407. \@\& [C] The \.{@\&} operation causes whatever is on its left to be
  408. adjacent to whatever is on its right, in the \cee\ output. No spaces or
  409. line breaks will separate these two items. \dots
  410. \@\^ [C,T] The ``control text'' that follows, up to the next
  411. `\.{@>}', will be entered into the index together with the identifiers of
  412. the \cee\ program; this text will appear in roman type. For example, to
  413. put the phrase ``system dependencies'' into the index, type
  414. `\.{@\^system dependencies@>}' in each module
  415. that you want to index as system dependent. A control text \dots\
  416. must end on the same line of the \.{WEB} file as it began.  Furthermore,
  417. no \.{WEB} control sequences are allowed in a control text, not even
  418. \.{@@}. (If you need an \.{@} sign you can get around this restriction by
  419. typing `\.{\\AT!}'.)
  420. \@. [C,T] The ``control text'' that follows will be entered into the index
  421. in \.{typewriter} \.{type}; see the rules for `\.{@\^}', which is analogous.
  422. \@: [C,T] The ``control text'' that follows will be entered into the index
  423. in a format controlled by the \TeX\ macro `\.{\\9}', which the user
  424. should define as desired; see the rules for `\.{@\^}', which is analogous.
  425. \@t [C] The ``control text'' that follows, up to the next `\.{@>}', will
  426. be put into a \TeX\ \.{\\hbox} and formatted along with the neighboring
  427. \cee\ program. This text is ignored by \.{TANGLE}, but it can be used
  428. for various purposes within \.{WEAVE}. For example, you can make comments
  429. that mix \cee\ and classical mathematics, as in `$\\{size}<2^{15}$', by
  430. typing `\.{|size < @t\$2\^\{15\}\$@>|}'.  A control text must end on the
  431. same line of the \.{WEB} file as it began, and it may not contain any
  432. \.{WEB} control codes.
  433. \@= [C] The ``control text'' that follows, up to the next `\.{@>}', will
  434. be passed verbatim to the \cee\ program.
  435. \@! [C,T] The module number in an index entry will be underlined if `\.{@!}'
  436. immediately precedes the identifier or control text being indexed. This
  437. convention is used to distinguish the modules where an identifier is
  438. defined, or where it is explained in some special way, from the modules
  439. where it is used. A~reserved word or an identifier of length one will not
  440. be indexed except for underlined entries. An `\.{@!}' is implicitly inserted
  441. by \.{WEAVE} [when an identified is being defined or declared in \cee\
  442. code; for example, the definition 
  443. \&{int} \\{array}[\\{max\_dim}], \\{count}${}=\\{old\_count};$
  444. makes the names \\{array} and \\{count} get an underlined entry in the
  445. index.  Statement tags, function definitions like
  446. $\\{main}(\\{argc},\39\\{argv})$ and \&{typedef} definitions also
  447. imply underlining.]
  448. \endnarrower
  449. \@' [C] This control code replaces the next character or escape sequence
  450. by its ASCII value.
  451. \narrower
  452. \@, [C] This control code inserts a thin space in \.{WEAVE}'s output; it is
  453. ignored by \.{TANGLE}. Sometimes you need this extra space if you are using
  454. macros in an unusual way, e.g., if two identifiers are adjacent.
  455. \@/ [C] This control code causes a line break to occur within a \cee\
  456. program formatted by \.{WEAVE}; it is ignored by \.{TANGLE}. Line breaks
  457. are chosen automatically by \TeX\ according to a scheme that works 99\%\
  458. of the time, but sometimes you will prefer to force a line break so that
  459. the program is segmented according to logical rather than visual
  460. criteria. \dots
  461. \@| [C] This control code specifies an optional line break in the midst of
  462. an expression. For example, if you have \dots\
  463. a long expression on the right-hand side of an assignment
  464. statement, you can use `\.{@|}' to specify breakpoints more logical than
  465. the ones that \TeX\ might choose on visual grounds.
  466. \@\# [C] This control code forces a line break, like \.{@/} does,
  467. and it also causes a little extra white space to appear between the lines at
  468. this break. You might use it, for example, \dots\
  469. between groups of macro definitions that are logically separate but within
  470. the same module. [\.{WEB} automatically inserts this extra space
  471. between functions, between external declarations and functions, and
  472. between declarations and statements within a function.]
  473. \@+ [C] This control code cancels a line break that might otherwise be
  474. inserted by \.{WEAVE}, e.g., before the word `\&{else}', if you want to
  475. put a short [if--else] construction on a single line. It is ignored by
  476. \.{TANGLE}.
  477. \@; [C] This control code is treated like a semicolon, for formatting
  478. purposes, except that it is invisible. You can use it, for example, after
  479. a module name when the \cee\ text represented by that module name ends
  480. with a semicolon.
  481. \yskip\noindent
  482. The last six control codes (namely `\.{@,}', `\.{@/}', `\.{@|}',
  483. `\.{@\#}', `\.{@+}', and `\.{@;}') have no effect on the \cee\
  484. program output by \.{TANGLE}; they merely help to improve the readability
  485. of the \TeX-formatted \cee\ that is output by \.{WEAVE}, in unusual
  486. circumstances. \.{WEAVE}'s built-in formatting method is fairly good
  487. [when dealing with syntactically correct \cee\ text], but
  488. it is incapable of handling all possible cases, because it must deal with
  489. fragments of text involving macros and module names; these fragments do
  490. not necessarily obey \cee's syntax. Although \.{WEB} allows you to
  491. override the automatic formatting, your best strategy is not to worry
  492. about such things until you have seen what \.{WEAVE} produces automatically,
  493. since you will probably need to make only a few corrections when you are
  494. touching up your documentation.
  495. \endnarrower
  496. Actually you may not like the way \.{WEAVE} handles certain
  497. situations, for examples, the fact that statements aren't always
  498. separated by newlines.  In that case you can customize \.{WEAVE}
  499. by changing its grammar.  In future releases you will be able
  500. to do so at run time, but for now you have to change the source
  501. code.  This is not hard; you can find a list of grammar rules
  502. in the \.{WEAVE} source listing or in the file \.{prod.web}.
  503. You can also compile \.{WEAVE} with the \.{-DDEBUG} option on the command
  504. line, and see how \.{WEAVE} is parsing your C code by preceding
  505. it with the line `\.{@ @c @2}' (the control sequence `\.{@2}'
  506. turns on the ``peeping'' mode, and `\.{@0}' turns it off).
  507. For example, if you run \.{WEAVE} on the file
  508. \medskip
  509. \begingroup
  510. \verbatim
  511. @ @c @2
  512. main (argc,argv)
  513. char **argv;
  514.     for (;argc>0;argc++)
  515.       printf("%s\n",argv[argc]);
  516. ?endgroup
  517. \endgroup
  518. \medskip\noindent
  519. you get the following gibberish on your screen:
  520. \medskip
  521. \begingroup
  522. \verbatim
  523. [...]
  524. 4:*exp ( +exp+ )...
  525. 27:*exp +exp+ int...
  526. 5:*+exp+ int +unorbinop+...
  527. [...]
  528. 31:*+fn_decl+ +stmt- -ignore_scrap-
  529. 20:*+function- -ignore_scrap-
  530. 56:*+function-
  531. [...]
  532. ?endgroup
  533. \endgroup
  534. \medskip
  535. The first line says that rule 4 has just been applied, and \.{WEAVE}
  536. currently has in its memory a sequence of chunks of C code (called
  537. ``scraps'') that are of type \\{exp} (for expression), open-parenthesis,
  538. \\{exp} again, close-parenthesis.  Then rule 27 is applied, and
  539. the sequence $(\,exp\,)$ becomes an \\{exp} and so on.  In the
  540. end the whole C text has become one big scrap of type \\{function}.
  541. Sometimes things don't work as smoothly, and you get a bunch of
  542. lines lumped together.  This means that \.{WEAVE} could not
  543. digest something in your C code.  For instance, if you had
  544. written \.{@<Argument definitions@>} instead of
  545. \.{char **argv;} in the program above \.{WEAVE} would have
  546. been completely mystified, since it thinks that module names
  547. are just \\{exp}s.  In this case you would have to help
  548. \.{WEAVE} by writing
  549. \begingroup
  550. \verbatim
  551. main (argc,argv)@/
  552. @<Argument definitions@>@;@/
  553. ?endgroup
  554. \endgroup
  555. \narrower
  556. \@{x @y @z}[\\{change\_file}]
  557. \.{WEAVE} and \.{TANGLE} are designed to work with two input files,
  558. called \\{web\_file} and \\{change\_file}, where \\{change\_file} contains
  559. data that overrides selected portions of \\{web\_file}. The resulting merged
  560. text is actually what has been called the \.{WEB} file elsewhere in this
  561. report.
  562. \hangindent 2em\hskip 2em
  563. Here's how it works: The change file consists of zero or more ``changes,''
  564. where a change has the form `\.{@x}$\langle$old lines$\rangle$\.{@y}$\langle$%
  565. new lines$\rangle$\.{@z}'. The special control codes \.{@x}, \.{@y}, \.{@z},
  566. which are allowed only in change files, must appear at the beginning of a line;
  567. the remainder of such a line is ignored.
  568. The $\langle$old lines$\rangle$ represent material that exactly matches
  569. consecutive lines of the \\{web\_file}; the $\langle$new lines$\rangle$
  570. represent zero or more lines that are supposed to replace the old. Whenever
  571. the first ``old line'' of a change is found to match a line in the
  572. \\{web\_file}, all the other lines in that change must match too.
  573. \hangindent 2em\hskip 2em
  574. Between changes, before the first change, and after the last change,
  575. the change file can have any number of lines that do not begin with
  576. `\.{@x}', `\.{@y}', or~`\.{@z}'. Such lines are bypassed and not used for
  577. matching purposes.
  578. \hangindent 2em\hskip 2em
  579. This dual-input feature is useful when working with a master \.{WEB} file
  580. that has been received from elsewhere (e.g., \.{TANGLE.WEB} or
  581. \.{WEAVE.WEB} or \.{TEX.WEB}), when changes are desirable to customize the
  582. program for your local computer system. You will be able to debug your
  583. system-dependent changes without clobbering the master web file; and once
  584. your changes are working, you will be able to incorporate them readily
  585. into new releases of the master web file that you might receive from time
  586. to time.
  587. \endnarrower
  588. \@i [\\{web\_file}] Furthermore the \\{web\_file} itself can be a combination of
  589. several files.  When \.{WEAVE} or \.{TANGLE} are reading a file and
  590. encounter the control code \.{@i} at the beginning of a line, they
  591. interrupt their reading and start reading the file named after the
  592. \.{@i}, much as the \cee\ preprocessor does when it encounters an \.{\#include}
  593. line.  After the included file is done, they go back to the next line
  594. of the original file.  The file name following \.{@i} can be
  595. surrounded by \." or not; it should be made up of visible ASCII
  596. characters only, not including \.".  Include files can nest.
  597. \narrower
  598. \section Additional features and caveats.
  599. 1. \dots\ In certain installations of \.{WEB} that
  600. {\def\\#1#2{`{\tentex\char'#1#2}'}%
  601. have an extended character set, the characters
  602. [\\13, \\01, \\31, \\32, \\34, \\35,
  603. \\36, \\37, and \\04}
  604. can be used as abbreviations for `\.{++}', `\.{--}', `\.{->}',
  605. `\.{!=}', `\.{<=}', `\.{>=}', `\.{==}', `\.{\v\v}', `\.{\&\&}',
  606. respectively.] However, the latter abbreviations
  607. are not used in the standard versions of \.{WEAVE.WEB} and \.{TANGLE.WEB}
  608. that are distributed to people who are installing \.{WEB} on other
  609. computers, and the programs are designed to produce only standard ASCII
  610. characters as output if the input consists entirely of ASCII characters.
  611. 2. If you have an extended character set, all of the characters listed
  612. in Appendix C of {\sl The \TeX book\/} can be used in strings. But you should
  613. stick to standard ASCII characters if you want to write programs that will
  614. be useful to all the poor souls out there who don't have extended
  615. character sets.
  616. 3. The \TeX\ file output by \.{WEAVE} is broken into lines having at most
  617. 80 characters each. The algorithm that does this line breaking is unaware
  618. of \TeX's convention about comments following `\.\%' signs on a line. When
  619. \TeX\ text is being copied, the existing line breaks are copied as well,
  620. so there is no problem with `\.\%' signs unless the original \.{WEB} file
  621. contains a line more than eighty characters long or a line with \cee\
  622. text in \pb\ that expands to more than eighty characters long. Such lines
  623. should not have `\.\%' signs.
  624. 4. \cee\ text is translated by a ``bottom up'' procedure that
  625. identifies each token as a ``part of speech'' and combines parts of speech
  626. into larger and larger phrases as much as possible according to a special
  627. grammar that is explained in the documentation of \.{WEAVE}. It is easy to
  628. learn the translation scheme for simple constructions like single
  629. identifiers and short expressions, just by looking at a few examples of
  630. what \.{WEAVE} does, but the general mechanism is somewhat complex because
  631. it must handle much more than \cee\ itself. Furthermore the output
  632. contains embedded codes that cause \TeX\ to indent and break lines as
  633. necessary, depending on the fonts used and the desired page width. For
  634. best results it is wise [not to] enclose long \cee\ texts in \pb, since the
  635. indentation and line breaking codes are omitted when the \pb\ text is
  636. translated from \cee\ to \TeX. Stick to simple expressions or
  637. statements.  [If a C preprocessor command is enclosed in \pb,
  638. the \.\# that introduces it must be at the beginning of a line,
  639. or \.{WEAVE} won't print it correctly.]
  640. 5. Comments and module names are not permitted in \pb\ text. After a `\.|'
  641. signals the change from \TeX\ text to \cee\ text, the next `\.|' that is
  642. not part of a string or control text ends the \cee\ text.
  643. 6. A comment must have properly nested occurrences of left and right
  644. braces, otherwise \.{WEAVE} [will try to balance the braces to keep
  645. \TeX\ from fouling up too much].
  646. 8. The \.{@f} feature allows you to define one identifier to act like
  647. another, and these format definitions are carried out sequentially
  648. \dots\ However, a given identifier has only one printed format
  649. throughout the entire document (and this format will even be used before
  650. the \.{@f} that defines it). The reason is that \.{WEAVE} operates in two
  651. passes; it processes \.{@f}'s and cross-references on the first pass and
  652. does the output on the second.
  653. 10. Sometimes it is desirable to insert spacing into \cee\ code that is
  654. more general than the thin space provided by `\.{@,}'. The \.{@t} feature
  655. can be used for this purpose; e.g., `\.{@t\\hskip 1in@>}' will
  656. leave one inch of blank space. Furthermore, `\.{@t\\4@>}' can be
  657. used to backspace by one unit of indentation, since the control sequence
  658. \.{\\4} is defined in \.{webmac} to be such a backspace. (This
  659. control sequence is used, for example, at the beginning of lines that
  660. contain labeled statements, so that the label will stick out a little at
  661. the left.)
  662. \endnarrower
  663. \section Appendices.
  664. The basic ideas of \.{WEB} can be understood most easily by looking at
  665. examples of ``real'' programs. Appendix~A shows the \.{WEB} input that
  666. generated modules 19--20 of the \.{COMMON} file, which contains
  667. routines common to \.{WEAVE} and \.{TANGLE}. Appendix~B shows the
  668. corresponding \TeX\ code output by \.{WEAVE},
  669. and Appendix~C shows how the output of \.{WEAVE} looks when printed out.
  670. Appendix~D shows the corresponding \cee\ code output by \.{TANGLE}, 
  671. Appendix E is the file that sets \TeX\ up to accept
  672. the output of \.{WEAVE}, Appendix~F discusses how to use some of its macros
  673. to vary the output formats.
  674. The reader should first compare Appendix~A to Appendix~D; then the
  675. same material should be compared to Appendices~B and~C.
  676. \vfil\eject
  677. \def\runninghead{APPENDIX A --- {\tentt WEB} FILE FORMAT}
  678. \section Appendix A.
  679. The following is an excerpt of the file \.{COMMON.WEB},
  680. which contains routines shared by \.{WEAVE} and \.{TANGLE}.
  681. Note that some of the lines are indented to show the program structure.
  682. The indentation is ignored by \.{WEAVE} and \.{TANGLE}, but users find
  683. that \.{WEB} files are quite readable if they have some such indentation.
  684. \vskip 6pt
  685. \begingroup \def\tt{\eighttt} \baselineskip9pt
  686. \verbatim
  687. @ The following procedure is used to see if the next change entry should
  688. go into effect; it is called only when |changing| is 0.
  689. The idea is to test whether or not the current
  690. contents of |buffer| matches the current contents of |change_buffer|.
  691. If not, there's nothing more to do; but if so, a change is called for:
  692. All of the text down to the \.{@@y} is supposed to match. An error
  693. message is issued if any discrepancy is found. Then the procedure
  694. prepares to read the next line from |change_file|.
  695. @<Func...@>=
  696. check_change() /* switches to |change_file| if the buffers match */
  697.   int n=0; /* the number of discrepancies found */
  698.   if (lines_dont_match) return;
  699.   while (1) {
  700.     changing=1; print_where=1; change_line++;
  701.     if (!input_ln(change_file)) {
  702.       err_print("! Change file ended before @@y");
  703. @.Change file ended...@>
  704.       change_limit=0; changing=0; print_where=1;
  705.       return;
  706.     }
  707.     @<Check for erron...@>;
  708.     @<If the current line starts with \.{@@y},
  709.       report any discrepancies and |return|@>;@/
  710.     @<Move |buffer| and |limit|...@>;@/
  711.     changing=0; print_where=1; cur_line++;
  712.     while (!input_ln(cur_file)) { /* pop the stack or quit */
  713.       if (include_depth==0) {
  714.         err_print("! WEB file ended during a change");
  715. @.WEB file ended...@>
  716.         input_has_ended=1; return;
  717.       }
  718.       include_depth--; print_where=1; cur_line++;
  719.     }
  720.     if (lines_dont_match) n++;
  721. @ @<If the current line starts with \.{@@y}...@>=
  722. if (limit>buffer+1 && buffer[0]==@'@@') {
  723.   @<Lowerc...@>;
  724.   if (buffer[1]==@'x' || buffer[1]==@'z') {
  725.     loc=buffer+2; err_print("! Where is the matching @@y?");
  726. @.Where is the match...@>
  727.     }
  728.   else if (buffer[1]==@'y') {
  729.     if (n>0) {
  730.       loc=buffer+2;
  731.       err_print("! Hmm... some of the preceding lines failed to match");
  732. @.Hmm... some of the preceding...@>
  733.     }
  734.     return;
  735. ?endgroup
  736. \endgroup
  737. \vfill\eject
  738. \def\runninghead{APPENDIX B --- TRANSLATION BY {\tentt WEAVE}}
  739. \section Appendix B.
  740. This excerpt from \.{COMMON.TEX} corresponds to Appendix A.
  741. \vskip6pt
  742. \begingroup \def\tt{\eighttt} \baselineskip9pt
  743. \verbatim
  744. \M19. The following procedure is used to see if the next change entry should
  745. go into effect; it is called only when \\{changing} is 0.
  746. The idea is to test whether or not the current
  747. contents of \\{buffer} matches the current contents of \\{change\_buffer}.
  748. If not, there's nothing more to do; but if so, a change is called for:
  749. All of the text down to the \.{@y} is supposed to match. An error
  750. message is issued if any discrepancy is found. Then the procedure
  751. prepares to read the next line from \\{change\_file}.
  752. \Y\P\4\X6:Functions\X${}+\S{}$\6
  753. $\\{check\_change}(\,)$\5
  754. \C{ switches to \\{change\_file} if the buffers match }\6
  755. $\{$\1\6
  756. \&{int} \|n$=\O{0};$\5
  757. \C{ the number of discrepancies found }\7
  758. \&{if} (\\{lines\_dont\_match})\1\5
  759. \&{return};\2\6
  760. \&{while} $(\O{1})$\5
  761. $\{$\1\6
  762. $\\{changing}=\O{1};$\5
  763. $\\{print\_where}=\O{1};$\5
  764. $\\{change\_line}\PP;$\6
  765. \&{if} $(\R\\{input\_ln}(\\{change\_file}))$\5
  766. $\{$\1\6
  767. $\\{err\_print}(\.{"!\ Change\ file\ ended\ before\ @y"});$\5
  768. $\\{change\_limit}=\O{0};$\5
  769. $\\{changing}=\O{0};$\5
  770. $\\{print\_where}=\O{1};$\5
  771. \&{return};\6
  772. \4$\}$\2\6
  773. \X16:Check for erroneous \.{@i}\X;\5
  774. \X20:If the current line starts with \.{@y}, report any discrepancies and %
  775. \&{return}\X;\6
  776. \X18:Move \\{buffer} and \\{limit} to \\{change\_buffer} and \\{change\_limit}%
  777. \X;\6
  778. $\\{changing}=\O{0};$\5
  779. $\\{print\_where}=\O{1};$\5
  780. $\\{cur\_line}\PP;$\6
  781. \&{while} $(\R\\{input\_ln}(\\{cur\_file}))$\5
  782. $\{$\5
  783. \C{ pop the stack or quit }\1\6
  784. \&{if} $(\\{include\_depth}\S\O{0})$\5
  785. $\{$\1\6
  786. $\\{err\_print}(\.{"!\ WEB\ file\ ended\ during\ a\ change"});$\5
  787. $\\{input\_has\_ended}=\O{1};$\5
  788. \&{return};\6
  789. \4$\}$\2\6
  790. $\\{include\_depth}\MM;$\5
  791. $\\{print\_where}=\O{1};$\5
  792. $\\{cur\_line}\PP;$\6
  793. \4$\}$\2\6
  794. \&{if} (\\{lines\_dont\_match})\1\5
  795. $\|n\PP;$\2\6
  796. \4$\}$\2\6
  797. \4$\}$\2\par
  798. \M20. \P\X20:If the current line starts with \.{@y}, report any discrepancies
  799. and \&{return}\X${}\S{}$\6
  800. \&{if} $(\\{limit}>\\{buffer}+\O{1}\W\\{buffer}[\O{0}]\S\.{@'@'})$\5
  801. $\{$\1\6
  802. \X15:Lowercasify $\\{buffer}[\O{1}]$\X;\6
  803. \&{if} $(\\{buffer}[\O{1}]\S\.{@'x'}\V\\{buffer}[\O{1}]\S\.{@'z'})$\5
  804. $\{$\1\6
  805. $\\{loc}=\\{buffer}+\O{2};$\5
  806. $\\{err\_print}(\.{"!\ Where\ is\ the\ matching\ @y?"});$\6
  807. \4$\}$\2\5
  808. \&{else} \1\&{if} $(\\{buffer}[\O{1}]\S\.{@'y'})$\5
  809. $\{$\1\6
  810. \&{if} $(\|n>\O{0})$\5
  811. $\{$\1\6
  812. $\\{loc}=\\{buffer}+\O{2};$\5
  813. $\\{err\_print}(\.{"!\ Hmm...\ some\ of\ the\ preceding\ lines\ failed\ to\
  814. match"});$\6
  815. \4$\}$\2\6
  816. \&{return};\6
  817. \4$\}$\2\2\6
  818. \4$\}$\2\par
  819. \U section~19.\fi
  820. ?endgroup
  821. \endgroup
  822. \vfil\eject
  823. \def\runninghead{APPENDIX C --- FINAL DOCUMENT}
  824. \section Appendix C.
  825. Here's what Appendix~B looks like when typeset.
  826. \M19. The following procedure is used to see if the next change entry should
  827. go into effect; it is called only when \\{changing} is 0.
  828. The idea is to test whether or not the current
  829. contents of \\{buffer} matches the current contents of \\{change\_buffer}.
  830. If not, there's nothing more to do; but if so, a change is called for:
  831. All of the text down to the \.{@y} is supposed to match. An error
  832. message is issued if any discrepancy is found. Then the procedure
  833. prepares to read the next line from \\{change\_file}.
  834. \Y\P\4\X6:Functions\X${}+\S{}$\6
  835. $\\{check\_change}(\,)$\5
  836. \C{ switches to \\{change\_file} if the buffers match }\6
  837. $\{$\1\6
  838. \&{int} \|n$=\O{0};$\5
  839. \C{ the number of discrepancies found }\7
  840. \&{if} (\\{lines\_dont\_match})\1\5
  841. \&{return};\2\6
  842. \&{while} $(\O{1})$\5
  843. $\{$\1\6
  844. $\\{changing}=\O{1};$\5
  845. $\\{print\_where}=\O{1};$\5
  846. $\\{change\_line}\PP;$\6
  847. \&{if} $(\R\\{input\_ln}(\\{change\_file}))$\5
  848. $\{$\1\6
  849. $\\{err\_print}(\.{"!\ Change\ file\ ended\ before\ @y"});$\5
  850. $\\{change\_limit}=\O{0};$\5
  851. $\\{changing}=\O{0};$\5
  852. $\\{print\_where}=\O{1};$\5
  853. \&{return};\6
  854. \4$\}$\2\6
  855. \X16:Check for erroneous \.{@i}\X;\5
  856. \X20:If the current line starts with \.{@y}, report any discrepancies and %
  857. \&{return}\X;\6
  858. \X18:Move \\{buffer} and \\{limit} to \\{change\_buffer} and \\{change\_limit}%
  859. \X;\6
  860. $\\{changing}=\O{0};$\5
  861. $\\{print\_where}=\O{1};$\5
  862. $\\{cur\_line}\PP;$\6
  863. \&{while} $(\R\\{input\_ln}(\\{cur\_file}))$\5
  864. $\{$\5
  865. \C{ pop the stack or quit }\1\6
  866. \&{if} $(\\{include\_depth}\S\O{0})$\5
  867. $\{$\1\6
  868. $\\{err\_print}(\.{"!\ WEB\ file\ ended\ during\ a\ change"});$\5
  869. $\\{input\_has\_ended}=\O{1};$\5
  870. \&{return};\6
  871. \4$\}$\2\6
  872. $\\{include\_depth}\MM;$\5
  873. $\\{print\_where}=\O{1};$\5
  874. $\\{cur\_line}\PP;$\6
  875. \4$\}$\2\6
  876. \&{if} (\\{lines\_dont\_match})\1\5
  877. $\|n\PP;$\2\6
  878. \4$\}$\2\6
  879. \4$\}$\2\par
  880. \M20. \P\X20:If the current line starts with \.{@y}, report any discrepancies
  881. and \&{return}\X${}\S{}$\6
  882. \&{if} $(\\{limit}>\\{buffer}+\O{1}\W\\{buffer}[\O{0}]\S\.{@'@'})$\5
  883. $\{$\1\6
  884. \X15:Lowercasify $\\{buffer}[\O{1}]$\X;\6
  885. \&{if} $(\\{buffer}[\O{1}]\S\.{@'x'}\V\\{buffer}[\O{1}]\S\.{@'z'})$\5
  886. $\{$\1\6
  887. $\\{loc}=\\{buffer}+\O{2};$\5
  888. $\\{err\_print}(\.{"!\ Where\ is\ the\ matching\ @y?"});$\6
  889. \4$\}$\2\5
  890. \&{else} \1\&{if} $(\\{buffer}[\O{1}]\S\.{@'y'})$\5
  891. $\{$\1\6
  892. \&{if} $(\|n>\O{0})$\5
  893. $\{$\1\6
  894. $\\{loc}=\\{buffer}+\O{2};$\5
  895. $\\{err\_print}(\.{"!\ Hmm...\ some\ of\ the\ preceding\ lines\ failed\ to\
  896. match"});$\6
  897. \4$\}$\2\6
  898. \&{return};\6
  899. \4$\}$\2\2\6
  900. \4$\}$\2\par
  901. \U section~19.\fi
  902. \vfil\eject
  903. \def\runninghead{APPENDIX D --- TRANSLATION BY {\tentt TANGLE}}
  904. \section Appendix D.
  905. Here's the portion of the \cee\ code generated by \.{TANGLE} that corresponds
  906. to Appendix~A.  Notice that module~15 has been tangled into module~20,
  907. and modules~16, 18 and~20 have been tangled into module~19.
  908. \vskip6pt
  909. \begingroup \def\tt{\eighttt} \baselineskip9pt
  910. \verbatim
  911. /*:13*//*19:*/
  912. #line 372 "common.web"
  913. check_change()
  914. int n= 0;
  915. if(lines_dont_match)return;
  916. while(1){
  917. changing= 1;print_where= 1;change_line++;
  918. if(!input_ln(change_file)){
  919. err_print("! Change file ended before @y");
  920. change_limit= 0;changing= 0;print_where= 1;
  921. return;
  922. /*16:*/
  923. #line 338 "common.web"
  924. if(buffer[1]==0151){
  925. loc= buffer+2;
  926. err_print("! No includes allowed in change file");
  927. /*:16*/
  928. #line 385 "common.web"
  929. /*20:*/
  930. #line 402 "common.web"
  931. if(limit>buffer+1&&buffer[0]==0100){
  932. /*15:*/
  933. #line 333 "common.web"
  934. if(buffer[1]>=0130&&buffer[1]<=0132||buffer[1]==0111)buffer[1]+= 0172-0132;
  935. /*:15*/
  936. #line 404 "common.web"
  937. if(buffer[1]==0170||buffer[1]==0172){
  938. loc= buffer+2;err_print("! Where is the matching @y?");
  939. else if(buffer[1]==0171){
  940. if(n>0){
  941. loc= buffer+2;
  942. err_print("! Hmm... some of the preceding lines failed to match");
  943. return;
  944. /*:20*/
  945. #line 387 "common.web"
  946. /*18:*/
  947. #line 357 "common.web"
  948. change_limit= change_buffer-buffer+limit;
  949. strncpy(change_buffer,buffer,limit-buffer+1);
  950. /*:18*/
  951. #line 388 "common.web"
  952. changing= 0;print_where= 1;cur_line++;
  953. while(!input_ln(cur_file)){
  954. if(include_depth==0){
  955. err_print("! WEB file ended during a change");
  956. input_has_ended= 1;return;
  957. include_depth--;print_where= 1;cur_line++;
  958. if(lines_dont_match)n++;
  959. /*:19*//*21:*/
  960. ?endgroup
  961. \endgroup
  962. \vfill\eject
  963. \def\runninghead{APPENDIX E --- MACROS FOR FORMATTING}
  964. \section Appendix E: The \.{cwebmac.tex} file.
  965. This is the file that extends ``plain \TeX'' format in order to support the
  966. features needed by the output of \.{WEAVE}.
  967. \vskip6pt
  968. \begingroup \def\tt{\eighttt} \baselineskip9pt
  969. \let\?=?
  970. \def\printmacs{\input cwebmac}
  971. \verbatim
  972. ?printmacs
  973. ?endgroup
  974. \endgroup
  975. \vfill\eject
  976. \narrower
  977. \def\runninghead{APPENDIX F --- NOTES ON FORMATTING}
  978. \section Appendix F: How to use \.{WEB} macros.
  979. The macros in \.{webmac} make it possible to produce a variety of formats
  980. without editing the output of \.{WEAVE}, and the purpose of this appendix
  981. is to explain some of the possibilities.
  982. \def\point#1.{\yskip\indent#1.\quad\ignorespaces}
  983. \point 1. Three fonts have been declared in addition to the standard fonts of
  984. \.{PLAIN} format: You can say `\.{\{\\sc stuff\}}' to get {\sc STUFF}
  985. in small caps; and you can select the largish fonts \.{\\titlefont}
  986. and \.{\\ttitlefont} in the title of your document, where \.{\\ttitlefont}
  987. is a typewriter style of type.
  988. \point 2. When you mention an identifier in \TeX\ text, you normally call
  989. it `\.{|identifier|}'. But you can also say `\.{\\\\\{identifier\}}'. The
  990. output will look the same in both cases, but the second alternative
  991. doesn't put \\{identifier} into the index, since
  992. it bypasses \.{WEAVE}'s translation from \cee\ mode.
  993. \point 3. To get typewriter-like type, as when referring to `\.{WEB}', you
  994. can use the `\.{\\.}' macro (e.g., `\.{\\.\{WEB\}}'). In the argument to
  995. this macro you should insert an additional backslash before the symbols
  996. listed as `special string characters' in the index to \.{WEAVE}, i.e.,
  997. before backslashes and dollar signs and the like.
  998. A `\.{\\\ }' here will result in the visible space symbol; to get an
  999. invisible space following a control sequence you can say `\.{\{\ \}}'.
  1000. [The `\.{\\)}' macro is similar to the preceding one, but instead
  1001. of putting the string in an hbox it prints it in as many lines as
  1002. necessary, with a backslash at the end of all but the last lines.
  1003. A space not preceded by a backslash is ignored by this macro.]
  1004. \point 4. The three control sequences \.{\\pagewidth}, \.{\\pageheight},
  1005. and \.{\\fullpageheight} can be redefined in the limbo section at the
  1006. beginning of your \.{WEB} file, to change the dimensions of each page.
  1007. The standard settings
  1008. $$\lpile{\.{\\pagewidth=6.5in}\cr
  1009.   \.{\\pageheight=8.7in}\cr
  1010.   \.{\\fullpageheight=9in}\cr}$$
  1011. were used to prepare the present report; \.{\\fullpageheight} is
  1012. \.{\\pageheight} plus room for the additional heading and page numbers at
  1013. the top of each page. If you change any of these quantities, you should
  1014. call the macro \.{\\setpage} immediately after making the change.
  1015. \point 5. The \.{\\pageshift} macro defines an amount by which right-hand
  1016. pages (i.e., odd-numbered pages) are shifted right with respect to
  1017. left-hand (even-numbered) ones. By adjusting this amount you may be
  1018. able to get two-sided output in which the page numbers line up on
  1019. opposite sides of each sheet.
  1020. \point 6. The \.{\\title} macro will appear at the top of each page
  1021. in small caps. \dots
  1022. \point 7. The first page usually is number 1; if you want some other
  1023. starting page, just set \.{\\pageno} to the desired number. \dots
  1024. \point 8. The macro \.{\\iftitle} will suppress the header line if it is
  1025. defined by `\.{\\titletrue}'. The normal value is \.{\\titlefalse}
  1026. except for the table of contents; thus, the contents
  1027. page is usually unnumbered. If your program is so long that the table of
  1028. contents doesn't fit on a single page, or if you want a number to appear
  1029. on the contents page, you should reset \.{\\pageno} when you begin the
  1030. table of contents.
  1031. Two macros are provided to give flexibility to the table of
  1032. contents: \.{\\topofcontents} is invoked just before the contents
  1033. info is read, and \.{\\botofcontents} is invoked just after.
  1034. [Here's a typical definition:]
  1035. $$\lpile{\.{\\def\\topofcontents\{\\null\\vfill}\cr
  1036.   \.{ { }\\titlefalse \% include headline on the contents page}\cr
  1037.   \.{ { }\\def\\rheader\{\\mainfont The \{\\tt WEAVE\}{ }processor\\hfil\}}\cr
  1038.   \.{ { }\\centerline\{\\titlefont The \{\\ttitlefont WEAVE\}{ }processor\}}\cr
  1039.   \.{ { }\\vskip 15pt \\centerline\{(Version 2.5)\}{ }\\vfill\}}\cr}$$
  1040. Redefining \.{\\rheader}, which is the headline for right-hand pages,
  1041. suffices in this case to put the desired information at the top of the page.
  1042. \point 9. Data for the table of contents is written to a file that
  1043. is read after the indexes have been \TeX ed; there's one line of data
  1044. for every starred module. [Here's what the
  1045. file \.{CONTENTS.TEX} might look like:
  1046. $$\lpile{\.{\\Z \{{ }Introduction\}\{1\}\{16\}}\cr
  1047.   \.{\\Z \{{ }The character set\}\{11\}\{19\}}\cr}$$
  1048. and so on.] The \.{\\topofcontents} macro could
  1049. redefine \.{\\Z} so that the information appears in another format.
  1050. \point 10. Sometimes it is necessary or desirable to divide the output of
  1051. \.{WEAVE} into subfiles that can be processed separately. For example,
  1052. the listing of \TeX\ runs to more than 500 pages, and that is enough to
  1053. exceed the capacity of many printing devices and/or their software.
  1054. When an extremely large job isn't cut into smaller pieces, the entire
  1055. process might be spoiled by a single error of some sort, making it
  1056. necessary to start everything over.
  1057. Here's a safe way to break a woven file into three parts:
  1058. Say the pieces are $\alpha$,
  1059. $\beta$, and $\gamma$, where each piece begins with a starred module.
  1060. All macros should be defined in the opening limbo section of $\alpha$,
  1061. and copies of this \TeX\ code should be placed at the
  1062. beginning of $\beta$ and of $\gamma$. In order to process the parts
  1063. separately, we need to take care of two things: The starting page
  1064. numbers of $\beta$ and $\gamma$ need to be set up properly, and
  1065. the table of contents data from all three runs needs to be
  1066. accumulated.
  1067. The \.{webmac} macros include two control sequences \.{\\contentsfile} and
  1068. \.{\\readcontents} that facilitate the necessary processing.  We include
  1069. `\.{\\def\\contentsfile\{CONT1\}}' in the limbo section of $\alpha$, and
  1070. we include `\.{\\def\\contentsfile\{CONT2\}}' in the limbo section of
  1071. $\beta$; this causes \TeX\ to write the contents data for $\alpha$ and $\beta$
  1072. into \.{CONT1.TEX} and \.{CONT2.TEX}. Now in $\gamma$ we say
  1073. $$\.{\\def\\readcontents\{\\input CONT1 \\input CONT2 \\input CONTENTS\}};$$
  1074. this brings in the data from all three pieces, in the proper order.
  1075. However, we still need to solve the page-numbering problem. One way to
  1076. do it is to include the following in the limbo material for $\beta$:
  1077. $$\lpile{\.{\\message\{Please type the last page number of part 1: \}}\cr
  1078.   \.{\\read-1to\\\\ \\pageno=\\\\ \\advance\\pageno by 1}\cr}$$
  1079. Then you simply provide the necessary data when \TeX\ requests
  1080. it; a similar construction is used at the beginning of $\gamma$.
  1081. This method can, of course, be used to divide a woven file into
  1082. any number of pieces.
  1083. \point 11. Sometimes it is nice to include things in the index that are
  1084. typeset in a special way. For example, we might want to have an
  1085. index entry for `\TeX'. \.{WEAVE} provides only two standard ways to
  1086. typeset an index entry (unless the entry is an identifier or a reserved word):
  1087. `\.{@\^}' gives roman type, and `\.{@.}' gives typewriter type.
  1088. But if we try to typeset `\TeX' in roman type by saying, e.g.,
  1089. `\.{@\^\\TeX@>}', the backslash character gets in the way,
  1090. and this entry wouldn't appear in the index with the T's.
  1091. The solution is to use the `\.{@:}' feature, declaring a macro that
  1092. simply removes a sort key as follows:
  1093. $$\.{\\def\\9\#1\{\}}$$
  1094. Now you can say, e.g., `\.{@:TeX\}\{\\TeX@>}' in your \.{WEB} file; \.{WEAVE}
  1095. puts it into the index alphabetically, based on the sort key, and
  1096. produces the macro call `\.{\\9\{TeX\}\{\\TeX\}}' which will ensure that
  1097. the sort key isn't printed.
  1098. A similar idea can be used to insert hidden material into module
  1099. names so that they are alphabetized in whatever way you might wish.
  1100. Some people call these tricks ``special refinements''; others call
  1101. them ``kludges''.
  1102. \point 12. The control sequence \.{\\modno} is set to the number of the
  1103. module being typeset.
  1104. \point 13. If you want to list only the modules that have changed,
  1105. together with the index, put the command `\.{\\let\\maybe=\\iffalse}' in
  1106. the limbo section before the first module of your \.{WEB} file. It's
  1107. customary to make this the first change in your change file.
  1108. \endnarrower
  1109. \vfill\end
  1110.